<?php

/*
 * This file is part of the FOSElasticaBundle package.
 *
 * (c) FriendsOfSymfony <https://friendsofsymfony.github.com/>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace FOS\ElasticaBundle\Configuration;

/**
 * @phpstan-import-type TConfig from IndexConfigInterface
 */
class IndexConfig implements IndexConfigInterface
{
    use IndexConfigTrait;

    /**
     * Indicates if the index should use an alias, allowing an index repopulation to occur
     * without overwriting the current index.
     *
     * @var bool
     */
    private $useAlias;

    /**
     * Constructor expects an array as generated by the Container Configuration builder.
     *
     * @phpstan-param TConfig $config
     */
    public function __construct(array $config)
    {
        $this->elasticSearchName = $config['elasticsearch_name'] ?? $config['name'];
        $this->name = $config['name'];
        $this->settings = $config['settings'] ?? [];
        $this->useAlias = $config['use_alias'] ?? false;
        $this->config = $config['config'];
        $this->mapping = $config['mapping'];
        $this->model = $config['model'];
    }

    public function isUseAlias(): bool
    {
        return $this->useAlias;
    }
}
